﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using PDFHelper.Helper;

namespace ITextSharpSample
{
    public partial class CreatePDF : PageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                iframeViewSwf.Visible = false;
            }
        }

        protected void btnGen_Click(object sender, EventArgs e)
        {
            Dictionary<string, object> dic = new Dictionary<string, object>();
            dic.Add("项目名称", txtProjectName.Text);
            dic.Add("核准机关名称", txtApproval.Text);
            dic.Add("招标事项核准文号", txtApprovalNumber.Text);
            dic.Add("投资主管部门名称",txtManagerDepart.Text);
             dic.Add("备案号",txtNumber.Text);
            dic.Add("项目业主",txtBidder.Text);
            dic.Add("建设地点",txtConAddress.Text);
            dic.Add("项目规模",txtProjectModel.Text);
            dic.Add("计划工期",txtDayNumber.Text);
            dic.Add("开工时间",DateTime.Parse(txtStart.Text));
            dic.Add("项目总投资",txtTotalMoney.Text);
            dic.Add("项目资金来源",txtMoenySource.Text);
            dic.Add("代理招标估算金额",txtAgcMoney.Text);
            dic.Add("资格等级",txtLevle.Text);
            dic.Add("资格",txtLevelNumber.Text);
            dic.Add("业绩要求",txtPerformanceCount.Text);
            dic.Add("分类项目业绩",txtPerformanceType.Text);
            dic.Add("项目负责人业绩要求",txtPMCount.Text);
            dic.Add("截止时间",DateTime.Parse(txtEndTime.Text));
            dic.Add("地点为",txtApplyAddress.Text);
            dic.Add("评审得分",txtAppravlNumber.Text);
            dic.Add("比 选 人",txtBidderName.Text);
            dic.Add("地    址",txtBidderAddress.Text);
            dic.Add("邮    编",txtbidderZipCode.Text);
             dic.Add("联 系 人",txtBidderContract.Text);
            dic.Add("电    话",txtPhone.Text);
             dic.Add("传    真",txtFax.Text);
             dic.Add("上网时间", DateTime.Parse(txtStartTime.Text));

             string fileName = Guid.NewGuid().ToString();
             using (var pdf = new PffNotice(Server.MapPath("~/Pdf/"+ fileName+".pdf")))
             {
                 pdf.Fill(dic);
             }

             if (TextSharpHelper.PDF2Swf(this.Pdf2Swf, Server.MapPath("~/Pdf/" + fileName + ".pdf"), Server.MapPath("~/swf/" + fileName + ".swf")))
             {

                 iframeViewSwf.Attributes.Add("src", string.Format("PdfView.aspx?file=" + fileName));
                 iframeViewSwf.Visible = true;
                 return;
             }

             iframeViewSwf.Visible = false;
        }
    }
}